//
//  FavoriteStoreCell.m
//  phmall
//
//  Created by admin on 2017/10/24.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "FavoriteStoreCell.h"

@implementation FavoriteStoreCell

- (void)awakeFromNib {
    [super awakeFromNib];

    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    FavoriteStoreCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[FavoriteStoreCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.backgroundColor=[UIColor groupTableViewBackgroundColor];
        self.back=[[UIView alloc]init];
        ViewBorderRadius(self.back, 5, 0, [UIColor clearColor]);
        self.back.backgroundColor=[UIColor whiteColor];
        [self.contentView addSubview:self.back];
       
        self.storeImage=[[UIImageView alloc]init];
        self.storeImage.image =[UIImage imageNamed:@"56ea394eNb5f936db"];
        ViewBorderRadius(self.storeImage, 5, 0, [UIColor whiteColor]);
        [self.contentView addSubview: self.storeImage];
        
        self.name=[[UILabel alloc]init];
        self.name.text=@"Jewelry store";
        self.name.font=[UIFont systemFontOfSize:18];
        [self.contentView addSubview:self.name];
        
        self.level=[[LevelImageView alloc]init];
        [self.contentView addSubview:self.level];
        
        
        self.remove=[UIButton  buttonWithType:UIButtonTypeCustom];
        [self.remove setImage:[UIImage imageNamed:@"垃圾箱"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.remove];
        [self.remove addTarget:self action:@selector(removeAction) forControlEvents:UIControlEventTouchUpInside];
        
        self.phone=[[UILabel alloc]init];
        self.phone.text=@"电话:8888-8888-8888";
        self.phone.font=[UIFont systemFontOfSize:13];
        self.phone.textColor=[UIColor colorWithHexString:@"#adadad"];
        [self.contentView addSubview:self.phone];
        
    }
    return self;
}
-(void)removeAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(removeFavoriteStore:)]) {
        [self.delegate removeFavoriteStore:self];
    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.right.equalTo(self.contentView).offset(-10);
        make.top.bottom.equalTo(self.contentView);
    }];
    
    [self.storeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.back).offset(10);
        make.bottom.equalTo(self.back).offset(-10);
        make.width.mas_equalTo(self.storeImage.mas_height);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.storeImage);
        make.left.equalTo(self.storeImage.mas_right).offset(10);
    }];
    
    [self.level mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.storeImage.mas_right).offset(10);
        make.centerY.equalTo(self.storeImage);
        make.right.equalTo(self.back).offset(-10);
        make.height.offset(20);
    }];
    
    [self.phone mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.storeImage);
        make.left.equalTo(self.storeImage.mas_right).offset(10);
    }];
    
    [self.remove mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).with.offset(-10);
        make.centerY.offset(0);
        make.width.height.offset(40);
    }];
}
-(void)setModel:(FavoriteModel *)model{
    _model=model;
    self.name.text=model.shop_name;
    [self.storeImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.shop_logo]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.phone.text=[NSString stringWithFormat:@"%@:%@",Localized(@"销保金额"),model.xb];
    self.level.score=[model.shop_name intValue];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
